import java.util.Stack;

public class Solution {
    public static String decodeString(String s) {
        StringBuilder curString = new StringBuilder();
        Stack<Integer> numStack = new Stack<>();
        Stack<StringBuilder> strStack = new Stack<>();
        int k = 0;

        for(char ch : s.toCharArray()){
            if (Character.isDigit(ch)) {
                k = k * 10 + (ch - '0');
            } else if (ch == '[') {
                numStack.push(k);
                strStack.push(curString);
                curString = new StringBuilder();
                k = 0;
            } else if (ch == ']') {
                int num = numStack.pop();
                StringBuilder decoded = strStack.pop();
                for (int i = 0; i < num; i++) {
                    decoded.append(curString);
                }
                curString = decoded;
            } else {
                curString.append(ch);
            }
        }

        return curString.toString();
    }

    public static void main(String[] args) {
        String s = "3[a2[c]]";
        System.out.println(decodeString(s));
    }
}
